<%@ page language="java" contentType="text/html" pageEncoding="utf-8" import="java.util.*, java.lang.*"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<h1>我的计算器</h1>
<hr></hr>
<form action="1.jsp" method="post">
请输入第一个数：<input type="text" name="one" ><br>
请选择运算方式：<select name="count">
<option value="+">+</option>
<option value="-">-</option>
<option value="*">*</option>
<option value="/">/</option>
</select><br>
请输入第二个数：<input type="text" name="two"><br>
<button type="submit">计算</button><button type="reset">重置</button><br>
</form>
<%
request.setCharacterEncoding("utf-8");
String one = request.getParameter("one");
String count = request.getParameter("count");
String two = request.getParameter("two");
if(count==null)
count="+";
if(one==null||two==null)
{
one="0.0";
two="0.0";
}
double b=0;
switch(count)
{
case "+":b=Double.parseDouble(one)+Double.parseDouble(two);break;
case "-":b=Double.parseDouble(one)-Double.parseDouble(two);break;
case "*":b=Double.parseDouble(one)*Double.parseDouble(two);break;
case "/":b=Double.parseDouble(one)/Double.parseDouble(two);break;
}
%>
结果：<input type="text" value="<%=b %>">
</body>
</html>